#ifndef CLIENT_HPP
#define CLIENT_HPP

#include <QSqlQuery>

#include <QObject>

#include "Commands.hpp"

class QTcpSocket;
class QXmlStreamReader;
class QSqlQuery;



class Client : public QObject
{
    Q_OBJECT
public:
    explicit Client(int socketDescriptor = 0,
                    QObject *parent = 0);
    ~Client();

    QTcpSocket  *socket() const;
    const int   socketDescriptor() const;

protected:

private:
    Q_DISABLE_COPY(Client)

    void writeXmlMessageSize(QByteArray &data);

    void parseXml(QByteArray& data);
    void parseCommand(QXmlStreamReader &xml);

    void parseAuthorisation(QXmlStreamReader &xml);
    void parseAllTransport(QXmlStreamReader &xml);
    void parseSearchOnNextMonth(QXmlStreamReader &xml);

    void queryAuthorisation(const QString &name, const QString &password);
    void querySearchOnNextMonth(const QString &date);
    void queryAllTransport();

    void answerAuthorisation(QSqlQuery &query);
    void answerSearchOnNextMonth(QSqlQuery &query);
    void answerAllTransport(QSqlQuery &query);

    QTcpSocket  *m_tcpSocket;
    USER_RIGHT  m_userRight;
    int         m_socketDescriptor;

signals:
    void query(QString &query, quint32 socket, COMMAND commandName);
    void disconnected();
public slots:
    void queryAnswer(QSqlQuery query, quint32 socket, COMMAND commandName);
private slots:
    void onReadyRead();
    void onDisconnected();

};

#endif // CLIENT_HPP
